package com.weiyuwqj.controller.reward;

import com.weiyuwqj.api.service.BusInvestService;
import com.weiyuwqj.api.service.BasUserInviteService;
import com.weiyuwqj.api.service.BasCouponService;
import com.weiyuwqj.api.service.BasTicketService;
import com.weiyuwqj.api.common.Paginator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhangyong on 2016/11/25.
 * 红包列表,加息列表
 */
@Controller
@RequestMapping("/user/reward")
public class RewardController {

    @Autowired
    BasCouponService couponService;
    @Autowired
    BasTicketService ticketService;
    @Autowired
    BasUserInviteService userInviteService;
    @Autowired
    BusInvestService investService;


    /**
     * 红包卡券页面
     * @return
     */
    @RequestMapping("")
    public Object reward(HttpServletRequest request) {
/*        Integer userId = (Integer) request.getSession().getAttribute("userId");
        BigDecimal addRateAmount = investService.countAddRateAmountByUserId(userId);
        BigDecimal useCouponAmount = couponService.countCouponAmountByStatusAndUserId(1, userId);
        BigDecimal rewardAmount = addRateAmount.add(useCouponAmount);
        request.getSession().setAttribute("addRateAmount", addRateAmount);
        request.getSession().setAttribute("useCouponAmount", useCouponAmount);
        request.getSession().setAttribute("rewardAmount", rewardAmount);*/
        return "main/user/reward";
    }

    /**
     * 红包列表
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/couponList")
    public Object getList(HttpServletRequest request,Paginator p,Integer status) {
        Integer userId = (Integer) request.getSession().getAttribute("userId");
        Map map = new HashMap();
        map.put("userId", userId);
        map.put("status",status);
        return couponService.listCouponAndConf(p, map);
    }

    /**
     * 加息券列表
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/ticketList")
    public Object getTicketList(HttpServletRequest request,Paginator p,Integer status){
        Integer userId = (Integer) request.getSession().getAttribute("userId");
        Map map=new HashMap();
        map.put("userId",userId);
        map.put("status",status);
        return ticketService.listTicketAndConf(p,map);
    }

    /**
     * 绑定邀请人
     * @param inviteCode
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/inviteBinding",method = RequestMethod.POST)
    public Object inviteBinding(HttpServletRequest request,String inviteCode){
        Integer userId = (Integer) request.getSession().getAttribute("userId");
        Map map=userInviteService.inviteBinding(userId,inviteCode);
        return map;
    }


}
